package logic

import (
	"context"
	"fmt"
	"we-chat-reg/model"

	"we-chat-reg/weixinrpc/internal/svc"
	"we-chat-reg/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectLogic) Perfect(in *weixinrpc.PerfectRequest) (*weixinrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line

	var WeiChat model.WeiChat
	model.DB.Debug().Where("tel=?", in.Tel).Find(&WeiChat)
	if WeiChat.ID == 0 {
		return nil, fmt.Errorf("该账号未注册")
	}
	model.DB.Debug().Updates(&WeiChat)
	return &weixinrpc.PerfectResponse{
		Id: int64(WeiChat.ID),
	}, nil
}
